
#include "stdafx.h"
#include "..\CppWrappers\CMTestClass.h"
#include "..\CppWrappers\CMTestClass2.h"
#include "..\CppWrappers\CMFactory.h"
#include "..\CppWrappers\CMITestInterface.h"
#include "..\CppWrappers\CMNullable_int.h"
#include "..\CppWrappers\CMByValueStruct.h"
#include "..\CppWrappers\CMDateTime.h"
#include "..\CppWrappers\CMDecimal.h"
#include "..\CppWrappers\CMTimeSpan.h"
#include "..\CppWrappers\CMException.h"

#include <sys/timeb.h>
#include <sys/types.h> 
#include <time.h>

using namespace ::DotNetClassLib;
using namespace ::System;

int _tmain(int argc, _TCHAR* argv[])
{
  try
  {
  CMTestClass::ThrowException();
  }
  catch (const CMException& e)
  {
    CString stack = e.StackTrace();
    printf("ExceptionStack: %s \n", stack);
  }


  CMTestClass cmTestClass("Blah");
  cmTestClass.Print();
  cmTestClass.Text = CString("test");
  cmTestClass.Text = cmTestClass.Text;
  cmTestClass.Print();

  Interfaces::CMITestInterface localInterface = CMFactory::GetTestInterface();
  CString test = localInterface.MakeUpper("dflaskehfb");
  cmTestClass.set_Text(test);
  cmTestClass.Print();

  if (cmTestClass.get_NullableInt().get_HasValue())
  {
    int i = cmTestClass.get_NullableInt().get_Value();
  }
  else

  {
    printf("no value\n");
    CString test;
 }
  vector<CString> array = cmTestClass.get_ArrayTestString();
  for(vector<CString>::iterator iter = array .begin(); iter!=array.end(); iter++)
  {
    wprintf((*iter));
    wprintf(_T("\n"));
  }

  vector<CMByValueStruct> valuearray = cmTestClass.get_ArrayTestByValue();
  int counter = 0;
  for(vector<CMByValueStruct>::iterator iter = valuearray .begin(); iter!=valuearray.end(); iter++)
  {
    counter++;
    (*iter).set_I(counter);
    wprintf(_T("%d\n"), (*iter).get_I());
  }

  CMTimeSpan timeSpan = cmTestClass.get_CurrentDateTime().AddDays(1) - CMDateTime::get_Now();

  wprintf(_T("%s\n"), ((CMObject)timeSpan).ToString());

  wprintf(_T("%s\n"), ((CMObject)cmTestClass.get_CurrentDateTime()).ToString());
  wprintf(_T("%s\n"), CMDateTime::get_Now().ToString("D"));

  CMNullable_int nInt(5);
  if (!nInt.get_HasValue())
  {
    wprintf(_T("no value"));
  }
  nInt = 4;
  if (nInt.get_HasValue())
  {
    int val = nInt;
    wprintf(_T("%d\n"), nInt.ToString());
  }

  printf("Test CMDateTime\n");
  time_t   start, finish;

  time( &start );
  for (int i = 0; i<10000000;i++)
  {
    CMDateTime dateTime(2000, 12,12);
  }
  time( &finish );


  double diff1 = difftime( finish, start );
  printf("%6.0f sec\n", diff1);

  printf("Test CTime\n");
  time( &start );
  for (int i = 0; i<10000000;i++)
  {
    CTime theTime(2000,12,12,0,0,0);
  }
  time( &finish );
  diff1 = difftime( finish, start );
  printf("%6.0f sec\n", diff1);
}
